# coding:utf8

from PyQt5.QtGui import QStandardItemModel, QStandardItem, QFont, QColor
from project.ipOnline.pack.container_ip import ContainerInList, Co_ntainer, ContainerTableData
from typing import  Union
from project import IpState
from project.ipOnline.pack.ping_ip import ManagerProxyThread




class CollectModel(QStandardItemModel):
    HeaderLabels = ["字段", "IP1", "IP2", "IP3", "IP4", "IP5", "IP6", "IP7", "IP8", "IP9", "IP10"]

    def __init__(self ):
        
        super(CollectModel, self).__init__()
        self.ctd = ContainerTableData()
        self.mpt = ManagerProxyThread()
        
        self.setColumnCount(len(self.HeaderLabels))
        self.setHorizontalHeaderLabels(self.HeaderLabels)
        pass
    
    def flush(self):
        
        self.removeRows(0, self.rowCount())
        datalistlist = self.ctd.out_print_data()
        if not datalistlist:  return
        
        for a_row_list in datalistlist:
            items = self._row_data(a_row_list)
            self.appendRow(items)
        
        
    
    def _row_data(self, a_row_list:list):
        
        if not a_row_list: return
       
        section = a_row_list[0].section()
        
        items = []
        first = QStandardItem("字段{}".format(section))
        items.append(first)
        for ipo in a_row_list:
            ipstr = ipo.ip
            
            item = QStandardItem(ipstr)
            color = ipo.get_color()
            if color:
                item.setBackground(color)
                
            items.append(item)
        return items
        
        
    def clear(self):
        self.ctd.clear()
        
    
        
        
        
     